package drawing 
{
	import flash.display.Graphics;
	/**
	 * ...
	 * @author Dmitriy Gaiduk
	 */
	public class DrawTool 
	{
		
		public function DrawTool() 
		{
			
		}
		
		/**
		 * Отрисовка фигуры, предыдущая точка является началом следующей
		 * edgePoints - points [[x,y], [x,y]...]
		 * line [x,y], curve [ancorX, ancorY, controlX, controlY]
		 * @param	surface
		 * @param	edgePoints 
		 */
		public static function drawEdge(surface:Graphics, edgePoints:Array):void
		{
			var pointsXY:Array;
			var prevPointsXY:Array;
			for (var i:int = 0; i < edgePoints.length; i++ )
			{
				pointsXY = edgePoints[i];
				if (i == 0)
				{
					surface.moveTo(pointsXY[0], pointsXY[1]);
				}else if (pointsXY.length == 2)
				{
					surface.lineTo(pointsXY[0] , pointsXY[1]);
				}else
				{
					//surface.curveTo(pointsXY[2], pointsXY[3], pointsXY[0], pointsXY[1]);
					var k:int = 0;
					while (k < pointsXY.length)
					{
						// pair points {x,y} start, control, end
						//points.push(prevXY[k], prevXY[k + 1], pointsXY[k + 2], pointsXY[k + 3], pointsXY[k], pointsXY[k + 1]);
						surface.curveTo(pointsXY[k+2], pointsXY[k + 3], 
									pointsXY[k], pointsXY[k+1]);
						k += 4;
					}				
				}
			}
		}
		
		
		/**
		 * отрисовка отдельных линий
		 * прямая [x1, y1, x2, y2]
		 * кривая Безье 2-го порядка [xStart, yStart, xEnd, yEnd, xControl, yControl]
		 * @param	surface
		 * @param	linesPoints
		 */
		public static function drawLines(surface:Graphics, linesPoints:Array):void
		{
			var pointsXY:Array;
			var prevPointsXY:Array;
			for (var i:int = 0; i < linesPoints.length; i++ )
			{
				pointsXY = linesPoints[i];
				if (pointsXY.length == 4)
				{
					// прямая линия
					surface.moveTo(pointsXY[0], pointsXY[1]);
					surface.lineTo(pointsXY[2] , pointsXY[3]);
				}else if (pointsXY.length == 6)
				{
					// кривая Безье
					surface.moveTo(pointsXY[0], pointsXY[1]);
					surface.curveTo(pointsXY[4], pointsXY[5], 
									pointsXY[2], pointsXY[3]);
				}else
				{
					// wrong line
				}
				
			}
		}
	}

}